﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using App.Common;
using DG.Tweening;
using QxFramework.Core;
public class EnemyRecover : EnemyBase
{
    private bool _judgeEnemy;
    public override void PlayerOutofRange(bool LostTarget, Vector3 otherDirect, GameObject Obj, Vector3 _targetDir)
    {
        base.PlayerInRange(LostTarget, otherDirect, Obj, _targetDir);
        if (LostTarget)
        {
            GetComponentInChildren<Animator>().SetBool("Walking", false);
            return;
        }
        //仅攻击暗属性玩家
        if (GameMgr.Get<IMonoManager>().GetMono(Obj.name).Attr != MonoAttribute.Dark)
        {
            _judgeEnemy = true;
            return;
        }

        JudgeLost(otherDirect);
        monoBase.Direction = otherDirect;
        monoBase.monoRealtimeStatus.AttackTips = false;

        if (monoBase.SkillList.Count > 1)
        {
            GetComponentInChildren<Animator>().SetBool("Walking", false);
            UseSkillJudge(monoBase.Direction.normalized, 1);
        }
        MoveByDirection(_targetDir, monoBase.Speed);
    }
    public override void PlayerInRange(bool LostTarget, Vector3 otherDirect, GameObject Obj, Vector3 _targetDir)
    {
        base.PlayerInRange(LostTarget, otherDirect, Obj, _targetDir);
        //仅攻击暗属性玩家
        if (GameMgr.Get<IMonoManager>().GetMono(Obj.name).Attr != MonoAttribute.Dark)
        {
            _judgeEnemy = true;
            return;
        }

        monoBase.Direction = otherDirect;
        if (GameMgr.Get<IMonoManager>().GetMono(Obj.name).Attr == monoBase.Attr && monoBase.Attr != MonoAttribute.None)
        {
            GetComponentInChildren<Animator>().SetBool("Walking", false);
            MoveByDirection(Quaternion.AngleAxis(90 * ((int.Parse(gameObject.name.Split('_')[1]) % 2 == 1) ? 1 : -1), Vector3.forward) * monoBase.Direction.normalized, -monoBase.Speed);
            return;
        }
        if (IsObstacleInLine(monoBase.Position, monoBase.Direction.normalized, 5, "Player"))
        {
            MoveByDirection(_targetDir, monoBase.Speed);
        }
        else
        {
            UseSkillJudge(monoBase.Direction.normalized, 0);
        }
    }
    public override bool JudgeEnemy()
    {
        return _judgeEnemy;
    }
    public override void EnemyOutofRange(bool LostTarget, Vector3 otherDirect, GameObject Obj, Vector3 _targetDir)
    {
        base.EnemyOutofRange(LostTarget, otherDirect, Obj, _targetDir);
        if (LostTarget)
        {
            GetComponentInChildren<Animator>().SetBool("Walking", false);
            return;
        }
        JudgeLost(otherDirect);
        monoBase.Direction = otherDirect;
        monoBase.monoRealtimeStatus.AttackTips = false;
        MoveByDirection(_targetDir, monoBase.Speed);
        _judgeEnemy = false;
    }
    public override void EnemyInRange(bool LostTarget, Vector3 otherDirect, GameObject Obj, Vector3 _targetDir)
    {
        base.EnemyInRange(LostTarget, otherDirect, Obj, _targetDir);
        //不攻击暗属性敌人
        if (GameMgr.Get<IMonoManager>().GetMono(Obj.name).Attr == MonoAttribute.Dark)
        {
            return;
        }
        monoBase.Direction = otherDirect;
        if (IsObstacleInLine(monoBase.Position, monoBase.Direction.normalized, 5, "Enemy"))
        {
            MoveByDirection(_targetDir, monoBase.Speed);
        }
        else
        {
            UseSkillJudge(monoBase.Direction.normalized, 0);
        }
        _judgeEnemy = false;
    }
    public override void UseSkillBase(Vector3 Direct, int SkillID, out bool ShootSuccess)
    {
        base.UseSkillBase(Direct, SkillID, out ShootSuccess);
        GameMgr.Get<ISkillManager>().UseSkill(monoBase, monoBase.SkillList[SkillID], monoBase.Position, Direct, GetComponent<CircleCollider2D>().radius + 0.2f, monoBase.Attr,99);
    }
}
